package com.zheng.controller;

import com.zheng.pojo.Result;
import com.zheng.pojo.User;
import com.zheng.util.CookieUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;


/**
 *  @author: zheng
 *  @Date: 2020-06-13 20:48
 *  @Description: 登陆
 */
@Controller
public class LoginController {

    @RequestMapping("/userLogin")
    @ResponseBody
    public Result userLogin(User user, HttpServletResponse response){
        if(user==null){
          return Result.build(400,"请求参数为空",null);
        }

        if("admin".equals(user.getUserName())&&"admin".equals(user.getPassword())){
            //登陆成功在cookie中设置token值
            CookieUtils.setCookie(response, "token", "admin", 60 * 60 );
            return Result.build(200,"请求成功",null);
        }

        return Result.build(400,"账号密码不存在",null);
    }

    @RequestMapping("/index")
    public String index(){
        return "index";
    }
}
